﻿var editor;
$(document).ready(function () {

    var aid = $("#aid").val();
    var acid = $("#acid").val();
    var aa = $("#contents").html();
    KindEditor.ready(function (K) {
        editor = KindEditor.create('#content', {
            resizeType: 2,
            uploadJson: '/System/Upload' // 相对于当前页面的路径
        });
        editor.html(aa);
    });
    $.ajax(
        {
            url: "/Case/GetCaseCategoryList",
            success: function (data) {
                var result = data;
                var str = "<option value=\"{0}\">{1}</option>";
                var dd = "";
                $(result).each(function () {
                    var temp = this;
                    var html = str.replace("{0}", temp.ID).replace("{1}", temp.ClassName);
                    dd = dd + html;
                });
                $("#categoryID").html(dd);

                // 如果是编辑文章
                if (aid != "") {
                    $("#categoryID").attr("value", acid);
                }
            },
            error: function () {
            }
        }
    );
});
function Save() {
    var categoryID = $("#categoryID :checked").val();
    var html;
    var title = $("#tb_title").val();
    if (title == "" || title == undefined) {
        alert("标题不能为空");
        return;
    }
    if (editor.html() == "" || editor.html() == undefined) {
        alert("内容不能为空");
        return;
    }
    $.ajax({
        url: "/Case/AddArticle",
        data: { "title": title, "classID": categoryID, "Content": editor.html(), "ID": $("#aid").val() },
        success: function (data) {
            if (data == 1) {
                alert("操作成功！");
            }
        },
        error: function (jqHR) {
            alert(jqHR + "操作失败");
        }

    });
}